package com.onesports.intelligent.k12.polarlight.util;

import java.util.Random;

/**
 * 字符串工具类
 * @author chenMJ
 * @since 2020-10-09 16:58
 */
public class StrUtils {

    /**
     * 随机生成数字+大写字母 字符串
     * @param num 生成位数
     * @return
     */
    public static String genRandomNum(int num){
        int  maxNum = 26;
        int i;
        int count = 0;
        char[] str = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
                'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
                'X', 'Y', 'Z' };
        StringBuffer pwd = new StringBuffer("");
        Random r = new Random();
        while(count < num){
            i = Math.abs(r.nextInt(maxNum));
            if (i >= 0 && i < str.length) {
                pwd.append(str[i]);
                count ++;
            }
        }
        return pwd.toString();
    }

    /**
     * 随机生成数字+小写字母 字符串
     * @param num 生成位数
     * @return
     */
    public static String genRandomLower(int num){
        int  maxNum = 36;
        int i;
        int count = 0;
        char[] str = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
                'l','m', 'n', 'o','p', 'q', 'r', 's', 't', 'u', 'v', 'w'};
        StringBuffer pwd = new StringBuffer("");
        Random r = new Random();
        while(count < num){
            i = Math.abs(r.nextInt(maxNum));
            if (i >= 0 && i < str.length) {
                pwd.append(str[i]);
                count ++;
            }
        }
        return pwd.toString();
    }

}
